package com.example.module_repair.repairnet

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.module_repair.R

class RepairAdapter : RecyclerView.Adapter<RepairAdapter.RepairViewHolder>() {

    private val iitems = mutableListOf<RepairModel>()

    fun setData(data: List<RepairModel>) {
        iitems.clear()
        iitems.addAll(data)
        notifyItemChanged(0, iitems.size)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepairViewHolder {
        return RepairViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_repair, parent, false)
        )
    }

    override fun getItemCount() = iitems.size


    override fun onBindViewHolder(holder: RepairViewHolder, position: Int) {
        holder.baoxiushijian.text = "${iitems[position].repairTime}"
        holder.repair_gongdanhao.text = "${iitems[position].orderNumber}"
        holder.repair_baoxiuren.text = "${iitems[position].repairName}"
        holder.repair_phone.text = "${iitems[position].contactMethod}"
        holder.repair_location.text = "${iitems[position].repairLocation}"
        holder.repair_guzhangmiaoshu.text = "${iitems[position].faultDescription}"
    }

    inner class RepairViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var baoxiushijian: TextView
        var repair_gongdanhao: TextView
        var repair_baoxiuren: TextView
        var repair_phone: TextView
        var repair_location: TextView
        var repair_guzhangmiaoshu: TextView


        init {
            baoxiushijian = view.findViewById(R.id.baoxiushijian)
            repair_gongdanhao = view.findViewById(R.id.repair_gongdanhao)
            repair_baoxiuren = view.findViewById(R.id.repair_baoxiuren)
            repair_phone = view.findViewById(R.id.repair_phone)
            repair_location = view.findViewById(R.id.repair_location)
            repair_guzhangmiaoshu = view.findViewById(R.id.repair_guzhangmiaoshu)
        }
    }
}